home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / YACC / landy.y < prev    next >
Encoding:
Text File  |  1990-11-05  |  1.2 KB  |  86 lines  |  [TEXT/KAHL]

  1. %union
  2. {
  3.     char   *tval;
  4.     int        ival;
  5.     float    fval;
  6.     long    lval;
  7. }
  8.  
  9. %term <tval> TCON
  10. %term <ival> ICON
  11. %term <fval> FCON
  12.  
  13. %type <tval> text
  14. %type <ival> integer
  15. %type <fval> real
  16. %{
  17. #define    YYDEBUG
  18. extern    int    yydebug;
  19. %}
  20.  
  21.  
  22. %%
  23.  
  24. dialog:        /* empty */ | dialog command;
  25.  
  26. command:    text integer real = {
  27.             printf("command: text = %s, integer = %d, real = %f\n",$1,$2,$3);
  28.             };
  29.  
  30. text:        TCON = {$<tval>$ = save(yytext);printf("YACC/TCON: %s\n", $<tval>$);};
  31.  
  32. integer:    ICON = {$<ival>$ = yyival;printf("YACC/ICON: %d\n", $<ival>$);};
  33.  
  34. real:        FCON = {$<fval>$ = yyfval;printf("YACC/FCON: %f\n", $<fval>$);};
  35.  
  36. %%
  37.  
  38. #include <stdio.h>
  39.  
  40. extern char yytext[];
  41. extern int yyival;
  42. extern float yyfval;
  43.  
  44. main()
  45. {
  46.     while(true) {
  47.         if(yyparse())
  48.             printf("Fail\n");
  49.         else
  50.             printf("Success\n");
  51.         llinit();
  52.         }
  53. }
  54.  
  55. #ifndef    THINK_C
  56. yyunion(to, from)
  57. YYSTYPE *to, *from;
  58. {
  59.     to->lval = from->lval;
  60. }
  61. #endif
  62.  
  63. yyerror(s)
  64. char *s;
  65. {
  66.     extern int yyline;
  67.  
  68.     if (yyline)
  69.         fprintf(stderr, "%d: ", yyline);
  70.     fprintf(stderr, "%s\n", s);
  71. }
  72.  
  73. char *
  74. save(s)
  75. char *s;
  76. {
  77.     char *t;
  78.     if(t = malloc(strlen(s)+1)) {
  79.         strcpy(t, s);
  80.         return(t);
  81.     } else {
  82.         printf("Out of Memory in save\n");
  83.         exit(1);
  84.     }
  85. }
  86.